<?php

	Class AdminloginAction extends  Action{

		/**
		 * 登录页面展示
		 */
		public function index(){
			
			$this->display();
		}
		/**
		 * 处理登陆数据
		 */
		public function loginHandle(){
			// dump($_POST);
			if(!$_POST)
				$this->error('warning.......');
			$members=M(members)->where(array('username'=>$_POST['username']))->find();
			//echo md5($_POST['password']);
			// dump($members);die;
			if($members){
				$password=md5($_POST['password']);
				if($password==$members['password']){
					//session('username',$members['username']);
					//
					 
					//M(members)->where(array('username'=>$_POST['username']))->setField('status',1);
					//echo "string";
                                        
                                        if($members['purview']==1){
                                        Session::set('username',$members['username']);  
					Session::set('uid',$members['uid']); 
                                        Session::set('purview',$members['purview']); 
                                            
					 $this->redirect(U('/index/index'), array(), 5,' 登录成功!,5秒钟后页面跳转中 ~') ;
                                        }
                                        else{
                                            
                                            $this->error('您的权限不够!');
                                            
                                        }
					//$this->success('login.....',U('/Index/index'));
				}else{
					$this->error('wrong password,please try again...');
				}
			}else{
				$this->error('wrong username,please try again...');
			}

		}
		/**
		 * 退出登录操作
		 */
		public function logout(){
			//M(members)->where(array('username'=>session('username')))->setField('status',0);
			Session::clear();
			$this->redirect(U('/index/index'), array(), 5,' 成功退出!,5秒钟后页面跳转中 ~') ;
			//$this->success('logouting...',U(GROUP_NAME.'/Login/index'));
		}
	}
?>